home *** CD-ROM | disk | FTP | other *** search
- /*
- * WWBloodShot.sl : a bloodshot shader derived from Larry Gritz's eyeball shader
- *
- * DESCRIPTION:
- * Makes a plastic-like surface which looks like the white part of an eyeball.
- * for use on a sphere. The center of the pupil is at the "north pole",
- * i.e. where the t parameter is 1. The colors of the pupil, iris, white
- * part (eyeball), and blood vessels can be set individually. Fractal
- * functions are used for the veining and the iris mottling.
- *
- * PARAMETERS:
- * Ka, Kd, Ks, roughness, specularcolor - work just like the plastic shader
- * eyeballcolor - color of the white part of the eyeball
- * bloodcolor - color of the blood vessels
- * bloodshot - controls how bloodshot the eye is (0=no blood, 1=very ugly)
- * veinfreq, veinlevel - control the formation of the blood vessels
- * index - set between 0 and 1, lets you use this shader to generate
- * non-identical eyeballs.
- *
- * AUTHOR: written by wave; hacked from Larry Gritz's eyeball shader
- *
- * HISTORY:
- * Nov 1991 - crude written of "eye" by lg for Herman's eyes for
- * "Graphic Violence". Original version hard coded in C.
- * Dec 1993 - "eye" modified by lg to clean up a bit.
- * 10 Jan 1994 - recoded by lg in correct shading language.
- * 28 Jun 94 (lg) - revamped to add veins and iris mottling, renamed
- * "eyeball"
- * 7 Jan 95 (wave) - changed name to LGEyeBall for namespace reasons...
- * 8 Jan 95 (wave) - changed Ciris line to fix bug Larry figured out and changed defaults
- * 15 Jan 95 (wave) - ripped out the iris and pupil stuff
- *
- * last modified 15 Jan 95 by Michael B. Johnson (wave)
- */
-
-
-
- surface
- WWBloodShot (float Ka = .75, Kd = 0.75, Ks = 0.4, roughness = 0.1;
- color specularcolor = 1;
- color eyeballcolor = color(1,1,1);
- color bloodcolor = color(.8,.05,.05);
- float bloodshot = 1.0;
- float irissize = 0.12;
- float veinfreq = 8, veinlevel = 4;
- float index = 0;
- )
- {
- #define snoise(P) (2*noise(P)-1)
- #define MINFILTERWIDTH 1.0e-7
- color Ct;
- point Nf;
- point PP, PO;
- float i, turb, newturb, freq, f2;
- float displayed, newdisp;
- color Cball, Ciris;
- float irisstat, pupilstat;
- float bloody, tt;
- float ks, rough;
- float twidth, cutoff;
-
- /* Calculate an appropriate filter width for antialiasing */
- twidth = max (abs(Du(t)*du) + abs(Dv(t)*dv), MINFILTERWIDTH);
- PO = transform ("object", P);
-
- /* Figure out where we are in the eyeball. Use the following variables:
- * irisstat: 0 inside the iris/white boundary, 1 outside
- * pupilstat: 0 inside the pupil/iris boundary, 1 outside
- * bloody: how potentially bloody it is (fade as we get away from iris)
- */
- tt = 1-t;
- irisstat = 1;
- pupilstat = 1;
- bloody = bloodshot * (smoothstep (-irissize, 2.5*irissize, tt));
-
- /* If we're somewhere in the white part and it's potentially bloody,
- * then calculate the veining pattern. Otherwise, just use the color
- * of the whites. The veining pattern is essentially summed zero sets
- * of turbulence functions. Some stretching is done to get it to look
- * just right.
- */
- if (irisstat * bloody > 0.001)
- { turb = bloody; freq = veinfreq;
- displayed = 0;
- for (i = 1; (i <= veinlevel) && (turb > 0.1); i += 1)
- { newturb = 1 - abs (snoise(PO*freq + point(0,0,20*freq)));
- newdisp = pow (smoothstep (.85, 1, newturb), 10);
- displayed += (1-displayed) * newdisp * smoothstep (.1, .85, turb * turb);
- turb *= newturb;
- freq *= 2;
- }
- Ct = mix (eyeballcolor, bloodcolor, smoothstep(0,.75,displayed));
- }
- else
- { Ct = eyeballcolor;
- }
-
- /* Now shade like plastic */
- Oi = Os;
- Nf = faceforward (normalize(N),I);
- Ci = Os * ( Ct * (Ka*ambient() + Kd*diffuse(Nf)) +
- specularcolor * Ks*specular(Nf,-normalize(I),roughness));
- }
-
-